package com.green.service.export;

import java.util.ArrayList;
import java.util.List;

import com.green.common.util.StringUtil;
import com.green.model.Entity;

/**
 * 数据导出模板信息
 * @author FengMy
 * @since 2012-4-12
 */
public class ExportView extends Entity<String> {
	private static final long serialVersionUID = -7019803347654252939L;
	private List<ExportItem> exportItems;
	private String name;
	private String number;
	public List<ExportItem> getExportItems() {
		return exportItems;
	}
	public void setExportItems(List<ExportItem> exportItems) {
		this.exportItems = exportItems;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	
	/**
	 * 用词组的方式生成列信息,方便动态构建,以split分隔
	 * ["name:display","name2:display"]
	 * @param str
	 * @param split
	 */
	public void setItemsByArray(String[] str,String split){
		if(str!=null && !StringUtil.isEmpty(split)){
			List<ExportItem> items = new ArrayList<ExportItem>();
			ExportItem item;
			for(String t : str){
				String[] ts = t.split(split);
				item = new ExportItem();
				item.setName(ts[0]);
				item.setDisplay(ts[1]);
				if(ts.length>2){
					item.setWidth(Integer.parseInt(ts[2])*36);
				}else{
					item.setWidth(100*36);
				}
				items.add(item);
			}
			this.setExportItems(items);
		}
	}
}
